package com.ps.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ps.property.TUserMessage;
import com.ps.service.LeaveWordService;
import com.ps.store.LeaveWordStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gt
 * @类说明：
 * @date 2020/10/27 19:23
 */
@Service
public class LeaveWordServiceImpl implements LeaveWordService {
    @Autowired
    LeaveWordStore leaveWordStore;

    @Override
    public int leaveWordAdd(TUserMessage tUserMessage) {
        return leaveWordStore.insert(tUserMessage);
    }

    @Override
    public IPage<TUserMessage> leaveWordQuery(int currentPage, int pageSize) {
        IPage<TUserMessage> iPage = new Page(currentPage,pageSize);

        iPage = leaveWordStore.selectPage(iPage,null);

        return iPage;
    }

    @Override
    public IPage<TUserMessage> leaveWordQueryByContacts(int currentPage, int pageSize, String contacts) {

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("contacts","%"+contacts+"%");

        IPage<TUserMessage> iPage = new Page(currentPage,pageSize);
        iPage = leaveWordStore.selectPage(iPage,wrapper);

        return iPage;
    }

    @Override
    public TUserMessage leaveWordQueryById(int leaveWordId) {
        QueryWrapper queryWrapper = new QueryWrapper();

        queryWrapper.eq("message_id",leaveWordId);

        return leaveWordStore.selectOne(queryWrapper);
    }

    @Override
    public int leaveWordUpdate(TUserMessage tUserMessage) {
        return leaveWordStore.updateById(tUserMessage);
    }
}
